package com.aso114.project.util;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.telephony.TelephonyManager;

/**
 * username:Created by hsj on 2016/10/11 0011.
 * class：
 * 类描述：手机帮助工具类
 */

public class HelperPhone {

    /**
     * 唯一的设备ID： GSM手机的 IMEI 和 CDMA手机的 MEID.
     *
     * @param context
     * @return
     */
    public static String getIMEI(Context context) {
        if(!islacksOfPermission(context,PERMISSION[0])){
            final TelephonyManager tm = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);
            return tm.getDeviceId();
        }
        return "";
    }

    private static String[] PERMISSION= {Manifest.permission.READ_PHONE_STATE};
    private static boolean islacksOfPermission(Context mContext,String permission){
        if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
            return ContextCompat.checkSelfPermission(mContext, permission) ==
                    PackageManager.PERMISSION_DENIED;
        }
        return false;
    }

}
